<%@ page import="java.util.ArrayList" %>
<%@ page import="employee.Employee" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 王宇航
  Date: 2023/3/10
  Time: 22:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>admin</title>
    <script>
        function del(){
            return confirm("delete this record?");
        }
    </script>
</head>
<body>
<%
    String name = (String) session.getAttribute("name");
    Object obj = session.getAttribute("role");
    int role = -1;
    if ( obj!= null){
        role= (int) session.getAttribute("role");
    }
    if (name != null && role == 1 ){
        out.println("<h1 style = \"color=\"green\"\">"+name+"</h1>");
    }else {
        session.setAttribute("error","Can't to Access adminPage!");
        response.sendRedirect("index.jsp");
    }
%>
<form action="/employee" method="post">
    <input type="hidden" name="action" value="Search">
    <input type="search" name="search" placeholder="Search In Name">
    <input type="submit" VALUE="Search">
</form>

<hr/>
<a href="addEmployee.jsp">Add Employee</a>
<table border="1">
    <tr>
        <th>id</th>
        <th>name</th>
        <th>age</th>
        <th>gender</th>
        <th colspan="3">operation</th>
    </tr>
    <c:forEach var="employee" items="${sessionScope.employees}">
        <tr>
            <td>${employee.id}</td>
            <td>${employee.name}</td>
            <td>${employee.age}</td>
            <td>${employee.gender}</td>
            <td><a href="/employee?action=Editer&id=${employee.getId() }">Editer</a></td>
            <td><a href="/employee?action=Remove&id=${employee.getId() }">Remove</a></td>
            <td><a href="/employee?action=Detail&id=${employee.getId() }">Detail</a></td>
        </tr>
    </c:forEach>
</table>
<hr/>
<a href="/employee?action=SignOut">Sign Out</a>
<p style="color: green">
    <%
        String message = (String) session.getAttribute("message");
        if (message != null){
            out.println(message);
        }
    %>
</p>
<p style="color: red">
    <%
        String error= (String) session.getAttribute("error");
        if (error != null){
            out.println(error);
        }
    %>
</p>
</body>
</html>
